Task Based Help / Formatting Reports / Editing the Field's Format Based on Value
In This Topic
Editing the Field's Format Based on Value
In This Topic

You can change a report field's format based on its value by specifying an expression for the Detail section's C1.C1Report.Section.OnFormat property.

To specify an expression for the C1.C1Report.Section.OnFormat property, complete the following steps:

  1. Open the C1ReportDesigner application. For more information on how to access C1ReportDesigner, see Accessing C1ReportDesigner from Visual Studio.
  2. Create a new report|tag=Creating a Basic Report Definition or open an existing report. Once you have the report in the C1ReportDesigner application, you can modify the report properties.
  3. Click the Close Print Preview button to begin editing the report.
  4. In Design mode, select Detail from the Properties window's drop-down list to view the available properties for the Detail section.
  5. Locate the C1.C1Report.Section.OnFormat property and click the ellipsis button next to the property.
  6. The VBScript Editor appears where you can specify an expression.

The following expression changes the UnitsInStock field's ForeColor to red if the sum of the UnitsInStock value and the UnitsOnOrder value is less than the ReorderLevel value. There are several ways to write this expression.

Option 1:

UnitsInStockCtl.Forecolor = Iif(UnitsInStock + UnitsOnOrder < ReorderLevel, vbRed, vbBlack)

Option 2:

lowStock = UnitsInStock + UnitsOnOrder < ReorderLevel

UnitsInStockCtl.Forecolor = Iif(lowStock, vbRed, vbBlack)

Option 3:

If UnitsInStock + UnitsOnOrder < ReorderLevel Then

    UnitsInStockCtl.Forecolor = vbRed

Else

    UnitsInStockCtl.Forecolor = vbBlack

End If

Option 4:

color = Iif(UnitsInStock + UnitsOnOrder < ReorderLevel, vbred, vbblack)

UnitsInStockCtl.Forecolor = color

This topic illustrates the following:

Notice that the Outback Lager's UnitsInStock value is formatted in red since the sum of the UnitsInStock and UnitsOnOrder is less than the ReorderLevel.

See Also